exports.UpdateTheUnread = function (req, res) {

    //获取参数信息
    var bodyParams = req.routeInfo.bodyParams;

    //返回结果
    var resultData = {};
    var datas = {};

    function sendDatas(){
        db.where({
            "s_id" : bodyParams.conversationId
        }).update({
            's_unread_count' : 0
        },"socket_session",(rs) => {
        })
        db.where({
            "s_id" : bodyParams.conversationId
        }).select("socket_session",(rs) => {
            if(rs.length != 0){
                db.where({
                    "s_send_id"    : rs[0].s_receive_id,
                    "s_receive_id" : rs[0].s_send_id
                }).update({
                    's_unread_count' : 0
                },"socket_session",(rs) => {
                })
            }
        })
    }

    //任务流创建
    async.waterfall([

        //根据会话列表id查询聊天记录
        //查询会话列表id查询发送人的u_username
        //根据会话列表id更新聊天记录是否已读状态
        //根据会话列表id更新会话列表未读条数字段
        (cb)=> {
            db.where({
                "hm_sid" : bodyParams.conversationId
            }).select("scoket_history_message",(rs) => {

                datas = rs
                cb()
            })
        },
        (cb) => {
            var task = [];

            datas.forEach(function (item,i) {
                //创建每一个插入任务
                task.push(function (cb) {
                    db.where({
                        "hm_id" : item.hm_id
                    }).update({
                        'hm_is_read' : 1
                    },"scoket_history_message",(rs) => {
                        cb();
                    })
                });

            });
            async.parallel(task, () => {
                cb();
            });
        },
    ],()=> {
        sendDatas();

        if(bodyParams.type != 1){
            resultData = datas
        }
        //返回最终拼接结果
        RES.successResponse(res,resultData);

    });
    
}